/*#define ledverte    PORTB.RB5
#define ledjaune    PORTB.RB4
#define ledbleue    PORTB.RB3
#define ledblanche    PORTB.RB2
#define ledrouge    PORTB.RB1

#define bblanc    PORTC.RC1
#define bjaune    PORTC.RC0
#define bvert    PORTC.RC2
#define bbleu    PORTC.RC3 */

/*// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D7 at RC4_bit;
sbit LCD_D6 at RC5_bit;
sbit LCD_D5 at RC6_bit;
sbit LCD_D4 at RC7_bit; */
// Lcd pinout settings
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;

/*// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISC4_bit;
sbit LCD_D6_Direction at TRISC5_bit;
sbit LCD_D5_Direction at TRISC6_bit;
sbit LCD_D4_Direction at TRISC7_bit;   */
// Pin direction
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;

char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){

  TRISA=0b00000000;
  PORTA=0b00000000;

  TRISB=0b00000000;
  PORTB=0b00000000;
  
  TRISC=0b00001111;
  PORTC=0b00001111;
  
 /* PWM2_Init(5000);
  PWM2_Set_Duty(25);
  PWM2_Start();  */

  
  //ledverte = 1 ;
  Delay_ms(500);
 // ledverte = 0 ;

  Lcd_Init();                        // Initialize LCD
 // ledverte = 1 ;
  Delay_ms(500);
 // ledverte = 0 ;

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  //Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row


  Lcd_Out(2,6,txt4);                 // Write text in second row
 // ledrouge = 1 ;
  Delay_ms(2000);
 // ledrouge = 0 ;

  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row
 // ledverte = 1 ;
  Delay_ms(2000);
 // ledverte = 0 ;

  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
   // ledrouge = 1 ;
    Move_Delay();
  }
 // ledrouge = 0 ;

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      //ledverte = 1 ;
      Move_Delay();
    }
    //ledverte = 0 ;

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      //ledrouge = 1 ;
      Move_Delay();
    }
    //ledrouge = 0 ;
  }
}